﻿using UnityEngine;
using UnityEngine.Events;
#if  UNITY_IOS&&!DEVELOP
using System.Runtime.InteropServices;
#endif
namespace QQSDK
{
    public class AdsManager : MonoBehaviour
    {
        public static AdsManager instance;
        public UnityAction<string> onGetAdvertismentID;
        private bool isInitAdsSucceed;
#if UNITY_EDITOR || DEVELOP
        [Header("编辑器中测试广告")]
        public GameObject fakeAdsPrefab;
#elif UNITY_IOS && !DELSDK
      
        [DllImport("__Internal")]
        private static extern void init();
        [DllImport("__Internal")]
        private static extern void loadSplash();
        [DllImport("__Internal")]
        private static extern void showSplash();
        [DllImport("__Internal")]
        private static extern void showBanner(bool isTop);
        [DllImport("__Internal")]
        private static extern void hideBanner();
        [DllImport("__Internal")]
        private static extern bool hasInterstitial();
          [DllImport("__Internal")]
        private static extern void loadInterAds();
        [DllImport("__Internal")]
        private static extern void showInterstitial();
        [DllImport("__Internal")]
        private static extern void showInterstitialWithScenes(string scenes);
        [DllImport("__Internal")]
        private static extern bool hasRewardVideo();
          [DllImport("__Internal")]
        private static extern void loadRewardAds();
        [DllImport("__Internal")]
        private static extern void showRewardVideo();
        [DllImport("__Internal")]
        private static extern void showRewardVideoWithScenes(string scenes);
        [DllImport("__Internal")]
        private static extern void showRewardVideoWithVerify(string customString);
        [DllImport("__Internal")]
        private static extern void agreeCOPPA(bool state);
        [DllImport("__Internal")]
        private static extern string getRealCountry();
        [DllImport("__Internal")]
        private static extern void loadNative(double weight,double height);
        [DllImport("__Internal")]
        private static extern bool hasNative();
        [DllImport("__Internal")]
        private static extern void showNative(double x,double y);
        [DllImport("__Internal")]
        private static extern void hideNative();
        [DllImport("__Internal")]
        private static extern bool hasIntersPage();
        [DllImport("__Internal")]
        private static extern void showIntersPageWithScenes(string scenes);
        [DllImport("__Internal")]
        private static extern void setAdSoundEnable(bool isEnable);
        [DllImport("__Internal")]
        private static extern void setTopOnChannel(string channel);
        [DllImport("__Internal")]
        private static extern void setTopOnSupChannel(string channel);
#elif UNITY_ANDROID
        public static AndroidJavaObject AJO;
#elif UNITY_WEBGL

#else

#endif
        private void Awake()
        {
            if (instance == null)
                instance = this;

#if UNITY_EDITOR || DEVELOP
            isInitAdsSucceed = true;
#elif UNITY_IOS && !DELSDK

#elif UNITY_ANDROID

#elif UNITY_WEBGL

#else
#endif
        }

        /// <summary>
        /// 设置广告
        /// </summary>
        public void Set()
        {
            SDKFunc.Log("设置广告");
#if UNITY_EDITOR || DEVELOP
            //在编辑器上初始化模拟广告系统
            if (fakeAdsPrefab != null)
            {
                GameObject fakeAdsInstantiate = Instantiate(fakeAdsPrefab);
                fakeAdsInstantiate.transform.SetParent(transform);
            }

            //在编辑器上模拟聚合初始化回调
            //TimerSchedule.Schedule(this, 2f, () =>
            //{
            //    AdsManager.instance.onInitAdsSucceed();
            //});
            Invoke("doOnInitAdsSucceed", 2);
#elif UNITY_IOS && !DELSDK
#elif UNITY_ANDROID
            AJO = SDKManager.SDK_Ads;
#elif UNITY_WEBGL

#else

#endif
        }


        public bool IsAdsInitSucceed()
        {
            return isInitAdsSucceed;
        }
        //通过ip地址获取用户的地理位置，需要在广告初始化完成后进行调用
        public string GetIPAddress()
        {
            string countryCode = string.Empty;
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
            countryCode = getRealCountry();
#elif UNITY_ANDROID
            if(AJO != null)
                countryCode = AJO.Call<string>("getRealCountry");
#elif UNITY_WEBGL

#else

#endif
            return countryCode;
        }

        public void doOnInitAdsSucceed()
        {
            if (AdsManager.instance.onInitAdsSucceed != null)
            {
                AdsManager.instance.onInitAdsSucceed();
            }
        }



        //        }
        /// <summary>
        /// Shows the banner. 展示开屏广告，
        /// </summary>
        /// <param name="isTop">If set to <c>true</c> is top.</param>
        public void LoadSplash(bool isFullScreen = false)
        {
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
            loadSplash();
#elif UNITY_ANDROID
            if(AJO != null)
                AJO.Call("loadSplash", SDKManager.GetCurrentlyActivity(), isFullScreen);
#elif UNITY_WEBGL

#else

#endif
        }
        /// <summary>
        /// Shows the banner. 展示banner广告
        /// </summary>
        /// <param name="isTop">If set to <c>true</c> is top.</param>
        public void ShowSplash()
        {
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
            showSplash();
#elif UNITY_ANDROID
            if(AJO != null)
                AJO.Call("showSplash", SDKManager.GetCurrentlyActivity());
#elif UNITY_WEBGL

#else

#endif
        }

        /// <summary>
        /// Shows the banner. 展示banner广告
        /// </summary>
        /// <param name="isTop">If set to <c>true</c> is top.</param>
        public void ShowBanner(bool isTop = false)
        {
#if UNITY_EDITOR || DEVELOP
            if (FakeAds.instance)
                FakeAds.instance.ShowBanner(isTop);
#elif UNITY_IOS && !DELSDK
            showBanner(isTop);
#elif UNITY_ANDROID
            if(AJO != null)
                AJO.Call("showBanner", SDKManager.GetCurrentlyActivity(), isTop);
#elif UNITY_WEBGL
#if HWGOOGLE || HWGUONEI
            webgtojs.instance.OnShowBannerEvent_HWGoogle();
#endif
#else

#endif
        }
        /// <summary>
        /// Hides the banenr.隐藏banner广告
        /// </summary>
        public void HideBanenr()
        {
#if UNITY_EDITOR || DEVELOP
            if (FakeAds.instance)
                FakeAds.instance.HideBanner();
#elif UNITY_IOS && !DELSDK
            hideBanner();
#elif UNITY_ANDROID
            if(AJO != null)
                AJO.Call("hideBanner");
#elif UNITY_WEBGL
#if HWGOOGLE || HWGUONEI
            webgtojs.instance.OnHideBannerEvent_HWGoogle();
#endif
#else
#endif
        }


        /// <summary>
        /// 加载插屏广告
        /// </summary>
        public void LoadInterstitial()
        {
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
            loadInterAds();
#elif UNITY_ANDROID
            if(AJO != null)
                AJO.Call("loadInterstitial",SDKManager.GetCurrentlyActivity());
#elif UNITY_WEBGL
#endif
        }

        /// <summary>
        /// Ises the available interstitial. 插屏广告是否可用 禁止在update函数中调用
        /// </summary>
        /// <returns><c>true</c>, if available interstitial was ised, <c>false</c> otherwise.</returns>
        public bool IsAvailableInterstitial()
        {
#if UNITY_EDITOR || DEVELOP
            return true;
#elif UNITY_IOS && !DELSDK
            return hasInterstitial();
#elif UNITY_ANDROID
            if(AJO != null)
                return AJO.Call<bool>("hasInterstitial", SDKManager.GetCurrentlyActivity());
            else
                return false;
#elif UNITY_WEBGL
#if HWGOOGLE || HWGUONEI
        return true;
#endif
        return false;
#else
        return false;
#endif
        }

        /// <summary>
        /// 播放插屏广告
        /// </summary>
        /// <param name="scenes">播放广告的page，用于区分不同页面的广告</param>
        public void ShowInterstitial(string scenes)
        {
#if UNITY_EDITOR || DEVELOP
            if (FakeAds.instance)
                FakeAds.instance.ShowInterstitial();
#elif UNITY_IOS && !DELSDK
            showInterstitialWithScenes(scenes);
#elif UNITY_ANDROID
            if(AJO != null)
                AJO.Call("showInterstitial", SDKManager.GetCurrentlyActivity(), scenes);
#elif UNITY_WEBGL
#if HWGOOGLE || HWGUONEI
          webgtojs.instance.showHWGoogleInterstitialEvent();
#endif 
#else
#endif
        }
        /// <summary>
        /// Ises the available interstitial. 插屏式插屏广告是否可用 禁止在update函数中调用
        /// </summary>
        /// <returns><c>true</c>, if available interstitial was ised, <c>false</c> otherwise.</returns>
        public bool IsAvailableIntersPage()
        {
#if UNITY_EDITOR || DEVELOP
            return false;
#elif UNITY_IOS && !DELSDK
            return hasIntersPage();
#elif UNITY_ANDROID
            if(AJO != null)
                return AJO.Call<bool>("hasIntersPage", SDKManager.GetCurrentlyActivity());
            else
                 return false;
#elif UNITY_WEBGL
            return false;
#else
            return false;
#endif
        }
        /// <summary>
        /// 播放插页式插屏广告
        /// </summary>
        /// <param name="scenes">播放广告的page，用于区分不同页面的广告</param>
        public void ShowIntersPage(string scenes)
        {
#if UNITY_EDITOR || DEVELOP
            if (FakeAds.instance)
                FakeAds.instance.ShowInterstitial();
#elif UNITY_IOS && !DELSDK
            showIntersPageWithScenes(scenes);
#elif UNITY_ANDROID
            if(AJO != null)
                AJO.Call("showIntersPage", SDKManager.GetCurrentlyActivity(), scenes);
#elif UNITY_WEBGL

#else
#endif
        }

        /// <summary>
        /// 加载激励广告
        /// </summary>
        public void LoadRewardVideo()
        {
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
            loadRewardAds();
#elif UNITY_ANDROID
            if(AJO != null)
                AJO.Call("loadRewardVideo",SDKManager.GetCurrentlyActivity());
#elif UNITY_WEBGL
#endif
        }
        /// <summary>
        /// Ises the available reward video.激励广告是否加载成功 禁止在update 中调用此函数
        /// </summary>
        /// <returns><c>true</c>, if available reward video was ised, <c>false</c> otherwise.</returns>
        public bool IsAvailableRewardVideo(string customString = "")
        {
#if UNITY_EDITOR || DEVELOP
            return true;
#elif UNITY_IOS && !DELSDK
            return hasRewardVideo();
#elif UNITY_ANDROID
            if(AJO != null)
                return AJO.Call<bool>("hasRewardVideo", SDKManager.GetCurrentlyActivity());
            else
                return false;
#elif UNITY_WEBGL
            return true;
#else
            return false;
#endif
        }
        /// <summary>
        /// Shows the reward video.播放激励视频
        /// </summary>
        //        public void ShowRewardVideoVerify(string customString)
        //        {
        //#if UNITY_EDITOR || DEVELOP
        //            if (FakeAds.instance)
        //                FakeAds.instance.ShowRewardVideo();
        //#elif UNITY_IOS && !DELSDK
        //            showRewardVideoWithVerify(customString);
        //#elif UNITY_ANDROID
        //            //todo 暂时不支持此接口
        //            // AJO.Call("showRewardVideo", SDKManager.GetCurrentlyActivity(), customString);
        //#elif UNITY_WEBGL

        //#else
        //#endif
        //        }
        /// <summary>
        /// Shows the reward video.播放激励视频.可传入场景名进行数据维度分析
        /// </summary>
        /// <param name="scenes">播放广告的page，用于区分不同页面的广告</param>
        public void ShowRewardVideo(string scenes)
        {
#if UNITY_EDITOR || DEVELOP
            if (FakeAds.instance)
                FakeAds.instance.ShowRewardVideo();
#elif UNITY_IOS && !DELSDK
            showRewardVideoWithScenes(scenes);
#elif UNITY_ANDROID
            if(AJO != null)
                AJO.Call("showRewardVideo", SDKManager.GetCurrentlyActivity(), scenes);
#elif UNITY_WEBGL
#if HWGOOGLE || HWGUONEI
            webgtojs.instance.showHWGoogleRewardEvent();
#endif
#else

#endif
        }
        /// <summary>
        /// Gets the IDC allback.Android获取手机的唯一id
        /// </summary>
        /// <param name="id">Identifier.</param>
        void GetIDCallback(string id)
        {
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
            //请直接调用ToolsManager.GetIOSIDFA()方法获取
#elif UNITY_ANDROID
            onGetAdvertismentID?.Invoke(id);
#elif UNITY_WEBGL

#else

#endif
        }


        public void AgreeCOPPA(bool state)
        {
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
            agreeCOPPA(state);
#elif UNITY_ANDROID
            if(AJO != null)
                AJO.Call("agreeCOPPA", state);
#elif UNITY_WEBGL

#else

#endif
        }

        //        public void LoadInterstitialAD()
        //        {
        //#if UNITY_EDITOR || DEVELOP

        //#elif UNITY_IOS && !DELSDK

        //#elif UNITY_ANDROID
        //            AJO.Call("loadInterstitialAd", SDKManager.GetCurrentlyActivity());
        //#elif UNITY_WEBGL

        //#else

        //#endif
        //        }

        //        public void LoadRewardedAD()
        //        {
        //#if UNITY_EDITOR || DEVELOP

        //#elif UNITY_IOS && !DELSDK

        //#elif UNITY_ANDROID
        //            AJO.Call("loadRewardedAd", SDKManager.GetCurrentlyActivity());
        //#elif UNITY_WEBGL

        //#else

        //#endif
        //        }

        /// <summary>
        /// 加载Native广告，先确定广告的大小
        /// </summary>
        /// <param name="weight"></param>
        /// <param name="height"></param>
        public void LoadNative(double weight, double height)
        {
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
                loadNative(weight,height);
#elif UNITY_ANDROID
            if(AJO != null)
                AJO.Call("loadNativeAd", SDKManager.GetCurrentlyActivity(),weight.ToString(), height.ToString());
#elif UNITY_WEBGL

#else

#endif
        }
        /// <summary>
        /// 判断Native广告是否加载完成
        /// </summary>
        /// <returns></returns>
        public bool IsAvailableNative()
        {
#if UNITY_EDITOR || DEVELOP
            return false;
#elif UNITY_IOS && !DELSDK
                return hasNative();
#elif UNITY_ANDROID
            if(AJO != null)
                return AJO.Call<bool>("hasNative");
            else
                 return false;
#elif UNITY_WEBGL
                return false;
#else
                return false;
#endif
        }
        /// <summary>
        /// 展示Native广告，需要传坐标参数
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public void ShowNative(double x, double y)
        {
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
                showNative(x,y);
#elif UNITY_ANDROID
            if(AJO != null)
                AJO.Call("showNativeAd", SDKManager.GetCurrentlyActivity(),x.ToString(), y.ToString());
#elif UNITY_WEBGL

#else

#endif
        }
        /// <summary>
        /// 隐藏Native广告，建议隐藏广告之后调用一次LoadNative，确保下次展示的时候能快速出现
        /// </summary>
        public void HideNative()
        {
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
                hideNative();
#elif UNITY_ANDROID
            if(AJO != null)
                AJO.Call("hideNative");
#elif UNITY_WEBGL

#else

#endif
        }


        /// <summary>
        /// 网赚项目使用。再登录成功，获取openid之后 调用
        /// </summary>
        /// <param name="wxid"></param>
        public void SetWXOpenId(string wxid)
        {
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK

#elif UNITY_ANDROID
            if(AJO != null)
                AJO.Call("setWXOpenId", wxid);
#elif UNITY_WEBGL

#else

#endif
        }

        //        public void SetAdSoundEnable(bool isEnable)
        //        {
        //#if UNITY_EDITOR || DEVELOP

        //#elif UNITY_IOS && !DELSDK
        //        setAdSoundEnable(isEnable);
        //#elif UNITY_ANDROID
        //        AJO.Call("setAdSoundEnable", isEnable);
        //#elif UNITY_WEBGL

        //#else

        //#endif
        //        }

        //        public void SetTopOnChannel(string channel)
        //        {
        //#if UNITY_EDITOR || DEVELOP

        //#elif UNITY_IOS && !DELSDK
        //        setTopOnChannel(channel);
        //#elif UNITY_ANDROID
        //        AJO.Call("setChannel", channel);
        //#elif UNITY_WEBGL

        //#else

        //#endif
        //        }

        //        public void SetTopOnSupChannel(string channel)
        //        {
        //#if UNITY_EDITOR || DEVELOP

        //#elif UNITY_IOS && !DELSDK
        //        setTopOnSupChannel(channel);
        //#elif UNITY_ANDROID
        //        AJO.Call("setSubChannel", channel);
        //#elif UNITY_WEBGL

        //#else

        //#endif
        //        }

        //        public void ShowOpenOrInstallAppDialog()
        //        {
        //#if UNITY_EDITOR || DEVELOP

        //#elif UNITY_IOS && !DELSDK
        //#elif UNITY_ANDROID
        //        AJO.Call("showOpenOrInstallAppDialog");
        //#elif UNITY_WEBGL

        //#else

        //#endif
        //        }

        //        public void SetDownloadDialog(bool isShow)
        //        {
        //#if UNITY_EDITOR || DEVELOP

        //#elif UNITY_IOS && !DELSDK
        //#elif UNITY_ANDROID
        //        AJO.Call("showAppDialog",isShow);
        //#elif UNITY_WEBGL

        //#else

        //#endif
        //        }

        //        public bool IsValidUser()
        //        {
        //#if UNITY_EDITOR || DEVELOP
        //            return true;
        //#elif UNITY_IOS && !DELSDK
        //            return true;
        //#elif UNITY_ANDROID
        //            return AJO.Call<bool>("isValidUser");
        //#elif UNITY_WEBGL
        //            return true;
        //#else
        //            return true;
        //#endif
        //        }


        private const string INIT_SUCCEED = "INIT_SUCCEED";
        private const string INIT_FAIL = "INIT_FAIL";

        private const string NEED_SHOW_GDPR = "NEED_SHOW_GDPR";
        private const string SPLASH_REQUEST = "SPLASH_REQUEST";
        private const string SPLASH_LOADED = "SPLASH_LOADED";
        private const string SPLASH_FAILED = "SPLASH_FAILED";
        private const string SPLASH_IMPRESSION = "SPLASH_IMPRESSION";

        private const string BANNER_IM = "BANNER_IMPRESSION";
        private const string BANNER_CLICK = "BANNER_CLICK";
        private const string BANNER_FAILED = "BANNER_FAILED";

        private const string INTERSTITIAL_REQUESTING = "INTERSTITIAL_REQUESTING";
        private const string INTERSTITIAL_LOADED = "INTERSTITIAL_LOADED";
        private const string INTERSTITIAL_FAILED = "INTERSTITIAL_FAILED";
        private const string INTERSTITIAL_OPEN = "INTERSTITIAL_OPEN";
        private const string INTERSTITIAL_CLICK = "INTERSTITIAL_CLICK";
        private const string INTERSTITIAL_CLOSE = "INTERSTITIAL_CLOSE";
        private const string INTERSTITIAL_PLAY_ERROR = "INTERSTITIAL_PLAY_ERROR";

        private const string REWARD_REQUESTING = "REWARD_REQUESTING";
        private const string REWARD_LOADED = "REWARD_LOADED";
        private const string REWARD_FAILED = "REWARD_FAILED";
        private const string REWARD_OPEN = "REWARD_OPEN";
        private const string REWARD_CLOSE = "REWARD_CLOSE";
        private const string REWARD_PLAY_ERROR = "REWARD_PLAY_ERROR";
        private const string REWARD_COMPLETE = "REWARD_COMPLETE";
        private const string REWARD_CLICK = "REWARD_CLICK";
        private const string USER_REWARD = "USER_REWARD";

        private const string NATIVE_LOADED = "NATIVE_LOADED";
        private const string NATIVE_FAILED = "NATIVE_FAILED";
        private const string NATIVE_CLICK = "NATIVE_CLICK";
        private const string NATIVE_OPEN = "NATIVE_OPEN";
        private const string NATIVE_CLOSE = "NATIVE_CLOSE";

        private const string INTERSPAGE_LOADED = "INTERSPAGE_LOADED";
        private const string INTERSPAGE_FAILED = "INTERSPAGE_FAILED";
        private const string INTERSPAGE_OPEN = "INTERSPAGE_OPEN";
        private const string INTERSPAGE_CLOSE = "INTERSPAGE_CLOSE";
        private const string INTERSPAGE_CLICK = "INTERSPAGE_CLICK";

        public UnityAction onInitAdsSucceed;
        public UnityAction onInitAdsFailed;

        public UnityAction onSplashRequest;
        public UnityAction onSplashLoadedFailed;
        public UnityAction onSplashLoaded;
        public UnityAction onSplashImpression;
        public UnityAction onBannerImpression;
        public UnityAction onBannerLoadedFailed;
        public UnityAction onBannerClick;

        public UnityAction onInterstitialRequest;
        public UnityAction onInterstitialLoaded;
        public UnityAction onInterstitialLoadedFailed;
        public UnityAction onInterstitialClick;
        public UnityAction onInterstitialOpen;
        public UnityAction onInterstitialPlayError;
        public UnityAction onInterstitialClose;

        public UnityAction onIntersPageLoaded;
        public UnityAction onIntersPageLoadedFailed;
        public UnityAction onIntersPageClick;
        public UnityAction onIntersPageOpen;
        public UnityAction onIntersPageClose;

        public UnityAction onNativeLoaded;
        public UnityAction onNativeLoadedFailed;
        public UnityAction onNativeClick;
        public UnityAction onNativeOpen;
        public UnityAction onNativeClose;

        public UnityAction onRewardRequest;
        public UnityAction onRewardLoaded;
        public UnityAction onRewardLoadFialed;
        public UnityAction onRewardOpen;
        public UnityAction onRewardClick;
        public UnityAction onRewardPlayError;
        public UnityAction onRewardInterrupt;
        public UnityAction onRewardComplete;
        public UnityAction onUserRewarded;

        public UnityAction<string> onImpressionDataCallback;
        public UnityAction<string> onAnalyticsCallback;
        public UnityAction<string> onReyunAttributionCallback;//新版本废弃
        public UnityAction<string> onAfUaMessageCallback;
        public UnityAction<string> onAfIPMessageCallback;
        public UnityAction<string> onRewardSecretKeyCallback;
        public UnityAction<string> onAbnormalUserCallback;
        public UnityAction<string> onAttributionObjectCallback;//新版本废弃
        public UnityAction<AttributionData> onAttributionDataCallback;

        public void AnalyticsCallback(string network)
        {
            SDKFunc.Log("adjustnetwork返回" + network);
            onAnalyticsCallback?.Invoke(network);
        }
        public void AbnormalUserCallback(string jsonStr)
        {
            SDKFunc.Log("第三方检测平台异常用户信息:" + jsonStr);
            onAbnormalUserCallback?.Invoke(jsonStr);
        }


        public void ImpressionCallback(string data)
        {
            SDKFunc.Log("用户级别的数据返回" + data);
            onImpressionDataCallback?.Invoke(data);
        }

        public void ReyunAttributionCallback(string attribution)
        {
            SDKFunc.Log("热云归因数据返回" + attribution);
            onReyunAttributionCallback?.Invoke(attribution);
        }
        public void AfUaMessageCallback(string afUaMessage)
        {
            SDKFunc.Log("AfUaMessageCallback" + afUaMessage);
            onAfUaMessageCallback?.Invoke(afUaMessage);
        }
        public void AfIPMessageCallback(string afIPMessage)
        {
            SDKFunc.Log("AfIPMessageCallback" + afIPMessage);
            onAfIPMessageCallback?.Invoke(afIPMessage);
        }
        public void RewardSecretKeyCallback(string secretKey)
        {
            SDKFunc.Log("激励密钥返回" + secretKey);
            onRewardSecretKeyCallback?.Invoke(secretKey);
        }

        public void AttributionOLDObject(string attribution)
        {
            SDKFunc.Log("归因数据返回" + attribution);
            onAttributionObjectCallback?.Invoke(attribution);
        }

        public void AttributionDataCallback(string attribution)
        {
            SDKFunc.Log("归因数据返回" + attribution);

            if (attribution.Contains("att_network"))
            {
                AttributionData attributionData = JsonMapper.ToObject<AttributionData>(attribution);
                onAttributionDataCallback?.Invoke(attributionData);
            }
            else
            {//string
                AttributionOLDObject(attribution);
            }
           
        }


        public void Callback(string message)
        {
            SDKFunc.Log("Callback:" + message);
            switch (message)
            {
                case INIT_SUCCEED:
                    isInitAdsSucceed = true;
                    onInitAdsSucceed?.Invoke();
                    break;
                case INIT_FAIL:
                    isInitAdsSucceed = false;
                    onInitAdsFailed?.Invoke();
                    break;
                case SPLASH_REQUEST:
                    onSplashRequest?.Invoke();
                    break;
                case SPLASH_LOADED:
                    onSplashLoaded?.Invoke();
                    break;
                case SPLASH_FAILED:
                    onSplashLoadedFailed?.Invoke();
                    break;
                case SPLASH_IMPRESSION:
                    onSplashImpression?.Invoke();
                    break;
                case BANNER_IM:
                    onBannerImpression?.Invoke();
                    break;
                case BANNER_FAILED:
                    onBannerLoadedFailed?.Invoke();
                    break;
                case BANNER_CLICK:
                    onBannerClick?.Invoke();
                    break;
                case INTERSTITIAL_REQUESTING:
                    onInterstitialRequest?.Invoke();
                    break;
                case INTERSTITIAL_LOADED:
                    onInterstitialLoaded?.Invoke();
                    break;
                case INTERSTITIAL_FAILED:
                    onInterstitialLoadedFailed?.Invoke();
                    break;
                case INTERSTITIAL_OPEN:
                    onInterstitialOpen?.Invoke();
                    break;
                case INTERSTITIAL_PLAY_ERROR:
                    onInterstitialPlayError?.Invoke();
                    break;
                case INTERSTITIAL_CLICK:
                    onInterstitialClick?.Invoke();
                    break;
                case INTERSTITIAL_CLOSE:
                    onInterstitialClose?.Invoke();
                    break;
                case INTERSPAGE_LOADED:
                    onIntersPageLoaded?.Invoke();
                    break;
                case INTERSPAGE_FAILED:
                    onIntersPageLoadedFailed?.Invoke();
                    break;
                case INTERSPAGE_OPEN:
                    onIntersPageOpen?.Invoke();
                    break;
                case INTERSPAGE_CLICK:
                    onIntersPageClick?.Invoke();
                    break;
                case INTERSPAGE_CLOSE:
                    onIntersPageClose?.Invoke();
                    break;
                case REWARD_REQUESTING:
                    onRewardRequest?.Invoke();
                    break;
                case REWARD_LOADED:
                    onRewardLoaded?.Invoke();
                    break;
                case REWARD_FAILED:
                    onRewardLoadFialed?.Invoke();
                    break;
                case REWARD_OPEN:
                    onRewardOpen?.Invoke();
                    break;
                case REWARD_PLAY_ERROR:
                    onRewardPlayError?.Invoke();
                    break;
                case REWARD_CLICK:
                    onRewardClick?.Invoke();
                    break;
                case REWARD_CLOSE:
                    onRewardInterrupt?.Invoke();
                    break;
                case REWARD_COMPLETE:
                    onRewardComplete?.Invoke();
                    break;
                case USER_REWARD:
                    onUserRewarded?.Invoke();
                    break;
                case NATIVE_LOADED:
                    onNativeLoaded?.Invoke();
                    break;
                case NATIVE_FAILED:
                    onNativeLoadedFailed?.Invoke();
                    break;
                case NATIVE_OPEN:
                    onNativeOpen?.Invoke();
                    break;
                case NATIVE_CLICK:
                    onNativeClick?.Invoke();
                    break;
                case NATIVE_CLOSE:
                    onNativeClose?.Invoke();
                    break;
            }
        }
    }


}